package interceptors

import (
	"github.com/gin-gonic/gin"
	"gpt-api/framework/auther"
	"gpt-api/framework/ginplus"
)

// Preflight 预检 中间件
func Preflight(a auther.Auther) gin.HandlerFunc {
	return func(c *gin.Context) {
		// parse token
		if t := ginplus.GetToken(c); t != "" {
			info, err := a.ParseUserID(t)
			if err == nil {
				ginplus.SetUserID(c, info.UserId)
			}
		}
	}
}
